﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
using System.Threading.Tasks;

namespace ExchangeHog.Util
{
	public class Util
	{
		public static string ConvertToUnsecureString(SecureString securePassword)
		{
			if (securePassword == null)
				throw new ArgumentNullException("securePassword");

			IntPtr unmanagedString = IntPtr.Zero;
			try
			{
				unmanagedString = Marshal.SecureStringToGlobalAllocUnicode(securePassword);
				return Marshal.PtrToStringUni(unmanagedString);
			}
			finally
			{
				Marshal.ZeroFreeGlobalAllocUnicode(unmanagedString);
			}
		}

		public static SecureString StringToSecureString(String s)
		{
			SecureString ss = new SecureString();
			foreach (char ch in (s.ToCharArray()))
				ss.AppendChar(ch);
			return ss;
		}
		
	}
}
